<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>{{$title}}</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
        content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="stylesheet" href="/xadmin/css/font.css">
    <link rel="stylesheet" href="/xadmin/css/xadmin.css">
    <script src="/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/xadmin/js/xadmin.js"></script>
</head>

<body>
    <div class="layui-fluid">
        <div class="layui-row">
            <form class="layui-form" action="">
                @csrf
                <div class="layui-form-item">
                    <label class="layui-form-label">Date selection</label>
                    <div class="layui-input-block" style="width: 300px;">
                        <select name="date" lay-verify="required">
                            <option value="">please select</option>
                            @for ($i = $currentDay+1; $i <= $carnivalDays; $i++)
                                <option value="{{$i}}">the {{$i}} day</option>
                            @endfor
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn" lay-submit lay-filter="formDemo">Reserve</button>
                        <button class="layui-btn" type="button" onclick="window.location.href='/dashboard'" >GoBack</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
    <script>
        layui.use(['form', 'layer'],
            function () {
                $ = layui.jquery;
                var form = layui.form,
                    layer = layui.layer;

                //监听提交
                form.on('submit(formDemo)', function(data){
                    let token = $("input[name='_token']").val();
                    $.ajax({
                        url: '/add_reserve',
                        type: 'POST',
                        dataType: 'json',
                        data: {'date': data.field.date, '_token': token},
                        success: function(res) {
                            // console.log(res);
                            if (res.status_code === 200) {
                                layer.msg(res.message, {icon: 1});
                                setTimeout(function(){
                                    window.location.href="/dashboard";
                                }, 2000);
                            } else {
                                layer.msg(res.message, {icon: 2});
                            }
                        }
                    })                    
                    return false;
                });

        });
    </script>
</body>

</html>